package org.beeware.android;

import android.app.Application;

import com.tencent.bugly.crashreport.CrashReport;

import org.beeware.android.util.ServiceUtil;

import java.util.Map;

public class MyApplication extends Application {

    private static final String BUGLY_APP_ID = BuildConfig.BUGLY_APP_ID;

    public static final int UPGRADE_APP_ID = BuildConfig.UPGRADE_APP_ID;

    private static MyApplication instance;

    public static MyApplication getInstance() {
        if (instance == null) {
            instance = new MyApplication();
        }
        return instance;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        //当前主进程，需要同步加载
        if (ServiceUtil.getProcessName(this).equals(getPackageName())) {
            CrashReport.UserStrategy strategy = new CrashReport.UserStrategy(this);
            strategy.setBuglyLogUpload(true);
            strategy.setEnableANRCrashMonitor(true);
            strategy.setEnableNativeCrashMonitor(true);
            strategy.setCrashHandleCallback(new CrashReport.CrashHandleCallback() {
                @Override
                public synchronized Map<String, String> onCrashHandleStart(
                        int arg0, String arg1, String arg2, String arg3) {
                    return super.onCrashHandleStart(arg0, arg1, arg2, arg3);
                }
            });
            CrashReport.initCrashReport(getApplicationContext(), BUGLY_APP_ID, false, strategy);
        }
    }
}
